//answer_comment_data
exports.answer_comment_data = function (req, res) {
    //获取restful参数
    var restfulParams = req.routeInfo.restfulParams;
    //最终结果
    var resultData = {};

    var limit = restfulParams.limit == undefined ? config.publicConfig.LIMIT : restfulParams.limit;

    var skip = restfulParams.skip == undefined ? 0 : restfulParams.skip;

    var answerData = 0;
    //任务流创建
    async.waterfall([
        //获取回答的评论
        function (cb) {

            R.SEND_HTTP(
                req,
                {
                    url: CORE_APIConfig.coreAPI.search_answer_comment_userinfo + "/fcac_fcaid/" + restfulParams.fca_id + "/fcac_fid/0" + "/skip/" + skip + "/limit/" + limit,
                    method: 'POST',
                    data: {
                        fields: [
                            "fcac_id as fcc_id",
                            "fcac_content as fcc_content",
                            "fcac_uid as fcc_uid",
                            "fcac_reply_uid as fcc_reply_uid",
                            "fcac_zan_count as fcc_zan_count",
                            "fcac_create_time as fcc_create_time",
                            "fcac_is_reply as fcc_is_reply",
                            "u_id",
                            "u_nickname",
                            "u_type",
                            "u_oid",
                            "u_header_url",
                        ].join(",")
                    }

                },
                function (err, data) {


                    resultData.answer_commentData = data.data;

                    cb();
                }
            );
        },
        function (cb) {

            var answer_commentData = resultData.answer_commentData;

            var tasks = [];

            answer_commentData.forEach(function (item, i) {

                tasks.push(function (cb) {
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.searchOrganization + "/o_uid/" + item.u_id,
                            method: 'POST',
                            data: {
                                fields: ["o_name", "o_logo"].join(",")
                            }
                        },
                        function (err, data) {

                            var organizationData = data.data[0];

                            if (data.data.length > 0) {
                                item.isOganization = 1;

                                item.o_name = organizationData.o_name;

                                item.o_logo = organizationData.o_logo;

                                cb();
                            } else {

                                item.isOganization = 0;
                                cb();
                            }

                        }
                    );

                })
            });
            async.waterfall(tasks, cb);
        },
        //查询当前用户是否对回答评论点赞
        function (cb) {

            //创建添加任务
            var tasks = [];

            //循环节点列表
            resultData.answer_commentData.forEach(function (item, i) {

                //创建每一个插入任务
                tasks.push(function (cb) {

                    //查询对该用户的回复
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.searchContentAnswerCommentZanRecord + "/is_delete/0/fcaczr_fcacid/" + item.fcc_id + "/fcaczr_uid/" + restfulParams.u_id,
                            method: 'POST',
                            data: {
                                fields: ["fcaczr_id"].join(",")
                            }

                        },
                        function (err, data) {

                            var is_exist = data.data;

                            if (is_exist.length <= 0) {
                                item.isZan = 0;
                            } else {
                                item.isZan = 1;
                            }
                            cb();
                        });
                });
            });
            async.waterfall(tasks, cb);

        },


        //查询该用户下的评论
        function (cb) {

            //创建添加任务
            var tasks = [];

            //循环节点列表
            resultData.answer_commentData.forEach(function (item, i) {

                //创建每一个插入任务
                tasks.push(function (cb) {
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.search_answer_comment_userinfo + "/fcac_fid/" + item.fcc_id + "/count/1",
                            method: 'POST',
                            data: {
                                fields: [
                                    "fcac_id as fcc_id",
                                    "fcac_content as fcc_content",
                                    "u_nickname",
                                    "u_type",
                                ].join(",")
                            }

                        },
                        function (err, data) {

                            item.replyCount = data.count;
                            item.replyData = data.data;


                            cb();
                        });

                });

            });

            async.waterfall(tasks, cb);

        },

    ], function (err, result) {

        //返回最终拼接结果
        RES.response(res, true, resultData);

    });

}